// 楼栋管理页面请求api
import httpInstance from './http'

// 1、获取所有的宿舍楼信息api
export const getBuildingsDataApi = (type, value = 0) => {
    // 0: 表示楼栋管理页面请求
    // 1：表示其他页面发送请求
    return httpInstance.get('/buildings', {
        params: { type, value }
    });
}

// 2、打开添加面板时请求所有的宿管数据
export const getDMDataApi = (id) => {
    if (Array.isArray(id)) {
        return httpInstance.get('/dormitory_mangers', {
            params: { id1: id[0], id2: id[1] }
        });
    }
    return httpInstance.get('/dormitory_mangers', {
        params: { id }
    });
}

// 3、添加楼栋信息Api
export const addBuildingInfoApi = (form) => {
    return httpInstance.post('/add_buildig', {
        data: form
    })
}

// 4、判断楼栋编号是否被使用
export const isUsedBuildingApi = (building_name) => {
    return httpInstance.get('/isUsedBuilding', {
        params: { building_name }
    })
}

// 5、按顺序获取楼栋编号
export const getNextBuildingName = () => {
    return httpInstance.get('/getNextBuildingName')
}

// 6、根据关键字进行搜索
export const searchBuildingApi = (searchObj) => {
    return httpInstance.get('/search_building', {
        params: searchObj
    })
}

// 7、获取编辑信息
export const getEditBuildingInfo = (id) => {
    return httpInstance.get('/getEditInfo', {
        params: { id }
    })
}

// 8、提交编辑后的信息
export const submitEditInfo = (form) => {
    return httpInstance.put('/uploadBuildingInfo', form)
}

// 9、删除
export const deleteBuildingApi = (id) => {
    return httpInstance.delete('/delete_building', {
        params: { id }
    })
}

// 10、启用宿舍楼
export const updateBuildingStatus = (id, value) => {
    return httpInstance.put('/update_bStatus', {
        id, value
    })
}